#! /bin/sh #接收外部参数
harbor_url="registry.cn-shanghai.aliyuncs.com"
harbor_project_name="jokerak"
project_name="clock"
tag='latest'
port='8081'
imageName=$harbor_url/$harbor_project_name/$project_name:$tag
echo "$imageName" #查询容器是否存在，存在则删除
containerId=`docker ps -a | grep -w ${project_name}:${tag} | awk '{print $1}'`
if [ "$containerId" != "" ] ; then
#停掉容器
  docker stop $containerId
#删除容器
  docker rm $containerId
  echo "成功删除容器"
fi
#查询镜像是否存在，存在则删除
imageId=`docker images | grep -w $project_name | awk '{print $3}'`
if [ "$imageId" != "" ] ; then
#删除镜像
 docker rmi -f $imageId
 echo "成功删除镜像"
fi
# 登录Harbor私服
docker login -u itcast -p Itcast123 $harbor_url
# 下载镜像
docker pull $imageName
# 启动容器
docker run -di -p $port:$port -v /etc/localtime:/etc/localtime $imageName
echo "容器启动成功"